home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FishMarket 1.0
/
FishMarket v1.0.iso
/
fishies
/
351-375
/
disk_370
/
sksh
/
stuff.sksh
< prev
next >
Wrap
Text File
|
1992-05-06
|
8KB
|
292 lines
#*************************************************************************
# This file contains functions and aliases which can be cut out and put
# in your .skshrc file. They are not included there by default, since
# many people will not want them, or will want modified versions.
# These commands should operate with SKsh version 1.3 or later.
# They are also simple skeletons which can be expanded to add features.
#
# Also, please note that these commands have not been tested extensively.
#*************************************************************************
#*************************************************************************
# This is a "man" function which can be used to retrieve documentation
# files stored in a MAN: directory. These files (which are often
# included with public domain software as "readme" files) should be
# copied to a name such as "MAN:prog.MAN". Then, "man prog" can be used
# to retrieve the files with the $PAGER command.
#*************************************************************************
function man {
if [ -z "$PAGER" ] then PAGER='more'; fi
if [ ! -f "MAN:$1.MAN" ]
then
echo "No manual entry for $1"
else
$PAGER "MAN:$1.MAN"
fi
}
#*************************************************************************
# This function accepts a number of parameters, and prompts the user
# for whether these files should be deleted. For example, "qrm *.o"
# would prompt the user at each .o file. Answering "Y" or "y" causes
# the file to be removed; otherwise, it is ignored. A useful extention
# would look at only the first character of the response, thus allowing
# "yes" to be used in place of "y".
#*************************************************************************
function qrm { # query rm
local ans
for file in $*
do
echo -n "Remove $file ? "
read ans
if [ "$ans" = 'y' -o "$ans" = 'Y' ]
then
rm -v "$file"
fi
done
}
#*************************************************************************
# This alias will remove emacs backup files by using the "qrm" function
# defined above. It could be extended to remove ".o" files, or anything
# else.
#*************************************************************************
alias clean='qrm *~'
#*************************************************************************
# The following functions implement directory push and pop operations.
# The first, pushd, accepts one argument. It cd's to that directory, but
# pushes the current working directory onto a stack, first, so that it
# can later be retrieved with a popd.
#*************************************************************************
function pushd {
if [ $# -ne 1 ]
then
echo "Usage: $0 new_dir"
elif [ ! -d "$1" ]
then
echo "$0: Can't cd to $1"
else
DIRSTACK="$PWD,$DIRSTACK"
export -l DIRSTACK
cd "$1"
fi
}
#*************************************************************************
# This function implements the popd operation. It accepts no arguments,
# and simply pops a directory off the stack and returns to that point.
# it complains if the directory stack is empty.
#*************************************************************************
function popd {
local comma_pos new_dir
if [ $# -ne 0 ]
then
echo "Usage: $0"
return
elif [ -z "$DIRSTACK" ]
then
echo 'The directory stack is empty'
return
fi
comma_pos = $(expr index "$DIRSTACK" ',')
new_dir = $(expr substr "$DIRSTACK" 1 $(expr $comma_pos - 1))
DIRSTACK = $(expr substr "$DIRSTACK" $(expr $comma_pos + 1) 32000)
export -l DIRSTACK
if cd "$new_dir"; then true
else echo "$0: Can't cd to $new_dir."
fi
}
#*************************************************************************
# These aliases clear and print the directory stack, respectively. The
# directory stack will be printed with a trailing comma, which is how it
# is stored. This could be cleaned up quite simply.
#*************************************************************************
alias cleard='DIRSTACK=""'
alias dstack='echo "$DIRSTACK"'
#*************************************************************************
# Ths function insert all files in the current directory except .o
# files into the current complist. It also inserts the contents of the
# COMPLIST variable.
#*************************************************************************
function cget {
complist -e
complist -a !*.o
complist -a $COMPLIST
}
#*************************************************************************
# Aliases and functions to make zoo files a bit easier to manipulate.
# The "zmore" function
#*************************************************************************
alias zp='zoo -print'
alias zl='zoo -list'
alias zx='zoo -extract'
alias za='zoo -add'
function zmore {
local zoofile tmpfile
if [ $# -lt 2 ]
then
echo "Usage: $0 zoofile file1..."
return;
fi
if [ -f "$1" ] then zoofile="$1"; else zoofile="$1.zoo"; fi
if [ ! -f "$zoofile" ]
then
echo "$0: $zoofile not found"
return
fi
shift
tmpfile="pipe:tmp_$CLINUM.$CMDNUM"
if [ -z "$PAGER" ] then PAGER='more'; fi
srun -o "$tmpfile" $(which zoo) -print "$zoofile" $*
$PAGER "$tmpfile"
}
#*************************************************************************
# This function insert all files from a 'zoo' archive into the current
# complist. They also insert the contents of the COMPLIST variable.
#*************************************************************************
function _zadd {
shift 2 # get rid of "Archive blah.zoo"
complist -a $*
}
function zget {
local zoofile zlist
if [ -f "$1" ] then zoofile="$1"; else zoofile="$1.zoo"; fi
if [ ! -f "$zoofile" ]
then
echo "$0: $zoofile not found"
return
fi
complist -e
zlist=$(zoo lf1 "$zoofile")
_zadd $zlist
complist -a $COMPLIST
}
#*************************************************************************
# This function extracts a zoo file in its own sub-directory, then
# deletes the original
#*************************************************************************
function zxdir {
local file dname zooname
for file in $*
do
dname=$(extname -v "$file")
zooname="$dname.zoo"
if [ ! -d "$dname" ] then mkdir "$dname"; fi
mv "$zooname" "$dname"; cd "$dname"
if zoo -extract "$zooname" >nil:
then
rm "$zooname"
else
echo "Extract Failed!"
fi
cd ..
done
}
#*************************************************************************
# This function sets emacs mode editing
#*************************************************************************
function emacs_mode {
setmap -r # reset the keymap
setmap -m 0 BOL '#' ACC # comment out line macro
setmap 0 8 BS 9 CC1 1 BOL 2 LFT 4 DEL 127 DEL 5 EOL 6 RHT \
7 ZAP 11 KEL 14 DN 15 EXE 16 UP 18 SRH 27 @1 155 @2 \
12 RDL 26 TIM 21 REP 20 SPC
setmap 1 27 CC1 = CC2 \* CC3 8 BDW f FWW b BKW d DLW \. ILP \
\/ ILT '<' HOL '>' TOL '#' '!0'
setmap 2 A UP B DN C RHT D LFT T HOL S TOL ' ' @3 \
48 FNK 49 FNK 50 FNK 51 FNK 52 FNK 53 FNK 54 FNK \
55 FNK 56 FNK 57 FNK
setmap 3 A BKW @ FWW
}
#*************************************************************************
# This function sets vi-mode editing
#*************************************************************************
function vi_mode {
setmap -r # reset the keymap
setmap -n 1
setmap -e 1 2
setmap -m 0 BOL GK0
setmap -m 1 EOL GK0
setmap -m 2 RHT GK0
setmap -m 3 BOL '#' ACC
setmap 0 27 @1 8 BS 9 CC1 12 RDL 155 @3 127 DEL 20 SPC
setmap 1 k UP j DN h LFT l RHT x DEL 10 ACC 13 ACC i @0 a '!2' \
d @2 27 CC1 $ EOL 48 BOL \/ SRH 155 @3 n SRH 8 BS w FWW \
W FWW b BKW B BKW - UP + DN D KEL R TIM _ ILP \* CC3 12 RDL \
= CC2 X BS 127 DEL A '!1' I '!0' '#' '!3'
setmap 2 w DLW $ KEL d ZAP c DEL
setmap 3 A UP B DN C RHT D LFT T HOL S TOL ' ' @4 \
48 FNK 49 FNK 50 FNK 51 FNK 52 FNK 53 FNK 54 FNK \
55 FNK 56 FNK 57 FNK
setmap 4 A BKW @ FWW
}